﻿
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Dictionary.Stock;
using WindowsForms.AOnline.Report.BaseParameterForm;
using WindowsForms.AOnline.Report.CommonClass;
using WindowsForms.AOnline.Session;
using WindowsForms.AOnline.View.Dictionary;

namespace WindowsForms.AOnline.Report.ParameterReportForm
{
    public partial class FrmStockBacklog : FrmXtraBaseParameter, IStocksView
    {
        private StocksPresenter _stocksPresenter;
        private GlobalVariable _dbOptionHelper;
        protected string CurrencyAccounting;
        protected string CurrencyAccountingUSD = "USD";
        public FrmStockBacklog()
        {
            InitializeComponent();
            _dbOptionHelper = new GlobalVariable();
            _stocksPresenter = new StocksPresenter(this);        
            
            dateTimeRangeV1.InitData(DateTime.Now);
            dateTimeRangeV1.SetComboIndex(7);
        }

        /// <summary>
        /// Gets or sets from date.
        /// </summary>
        /// <value>
        /// From date.
        /// </value>
        public DateTime FromDate
        {
            get
            {
                return dateTimeRangeV1.FromDate;
            }
            set
            {
            }
        }

        /// <summary>
        /// Gets or sets the reference date.
        /// </summary>
        /// <value>
        /// The reference date.
        /// </value>
        public DateTime ToDate
        {
            get
            {
                return dateTimeRangeV1.ToDate;
            }
            set
            {
            }
        }

        /// <summary>
        /// Gets or sets the employee identifier.
        /// </summary>
        /// <value>
        /// The employee identifier.
        /// </value>
        public string ListStockId
        {
            get
            {
                string listKey = "";
                var list = cboStock.Properties.GetItems().GetCheckedValues();
                foreach (var key in list)
                {
                    listKey = listKey + "," + key.ToString();
                }
                listKey = listKey.Remove(0, 1);
                return listKey;
            }

        }

        public string StockName
        {
            get
            {
                return cboStock.Text;
            }
        }

        private void FrmStockBacklog_Load(object sender, EventArgs e)
        {
            _stocksPresenter.GetAll();
            CurrencyAccounting = _dbOptionHelper.CurrencyAccounting;
        }

        public IList<Model.BusinessObjects.Dictionary.StockModel> Stocks
        {
            set
            {
                if (value == null) return;
                cboStock.Properties.DataSource = value;
                var colColection = new List<XtraColumn>();
                colColection.Clear();

                colColection.Add(new XtraColumn { ColumnName = "StockCode", ColumnCaption = "Mã kho", ToolTip = "Mã kho", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 100, Alignment = HorzAlignment.Center });
                colColection.Add(new XtraColumn { ColumnName = "StockName", ColumnCaption = "Tên kho", ToolTip = "Tên kho", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 100, Alignment = HorzAlignment.Center });
                colColection.Add(new XtraColumn { ColumnName = "StockId", ColumnCaption = "", ColumnVisible = false });
                colColection.Add(new XtraColumn { ColumnName = "IsActive", ColumnCaption = "", ColumnVisible = false });
                colColection.Add(new XtraColumn { ColumnName = "Description", ColumnCaption = "", ColumnVisible = false });
                foreach (var column in colColection)
                {
                    if (column.ColumnVisible)
                    {
                    }
                }
                cboStock.Properties.DisplayMember = "StockName";
                cboStock.Properties.ValueMember = "StockId";
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (dateTimeRangeV1.FromDate.ToString() == "")
            {
                XtraMessageBox.Show("Bạn chưa chọn ngày tính giá", "Lỗi");
                return;
            }
            if (dateTimeRangeV1.ToDate.ToString() == "")
            {
                XtraMessageBox.Show("Bạn chưa chọn ngày tính giá", "Lỗi");
                return;
            }
            if (cboStock.Text.ToString() == "")
            {
                XtraMessageBox.Show("Bạn chưa chọn kho", "Lỗi");
                return;
            }
            DialogResult = DialogResult.OK;
        }
    }
}
